<?php

/**
 * JavaScript Import
 * @author ReGeDa
 */
class JavaScript extends Plugin_Object {

	/**
	 * Require scripts
	 * @var array
	 */
	private $scripts = array();

	/**
	 * Get persistant plugin state
	 * @override
	 * @return boolean
	 */
	public function is_persistant() {
		return TRUE;
	}

	/**
	 * Constructor
	 */
	public function  __construct() {
		parent::__construct();
		platcode()->raw['import-js'] = &$this->scripts;
	}

	/**
	 * Import JavaScript file into viewer
	 * @param string|array $filename
	 */
	public function &lib($filename) {
		if (is_array($filename))
			$this->scripts = array_merge($this->scripts, $filename);
		else
			array_push($this->scripts, $filename);

		// cascade caller
		return $this;
	}

	/**
	 * Import JavaScript internalization file into viewer
	 * Language name is taked from config ./system/config/platcode.php
	 * @param string|array $filename
	 */
	public function &lang($filename) {

		// convert string to input array
		if (is_string($filename))
			$filename = array($filename);

		$lang = config('language');

		foreach ($filename as $file)
			array_push($this->scripts, "i18n/$lang/$file");

		// cascade caller
		return $this;
	}
}

// end of file;